package day17;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Map02 {
    public static void main(String[] args) {
        //键值对方法遍历

        //增强for遍历
        Map<String,String> map = new HashMap<>();
        map.put("KFC", "香辣鸡腿堡");
        map.put("麦当劳","麦辣鸡腿堡");
        map.put("塔斯汀","中国汉堡");

        for (Map.Entry<String,String> entry : map.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+":"+value);
        };

        //Lambda方法
        map.forEach((k,v)->{System.out.println(k+":"+v);});

        //迭代器遍历
        Iterator<Map.Entry<String,String>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String,String> entry = iterator.next();
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+":"+value);
        }
    }
}
